import { NIcon } from 'naive-ui'
import { h, Component } from 'vue'
export function renderIcon(icon: Component) {
    return () => h(NIcon, null, { default: () => h(icon) })
}

export function isLogin(id: string | number) {
    return id != null && id != ''
}

export function handlePlayCount(num: number) {
    if (num > 10000000) {
        return (num / 1000000).toFixed(2) + '百万'
    } else if (num > 100000) {
        return (num / 10000).toFixed(2) + '万'
    } else {
        return num
    }
}

export function pad(num, n = 2) {
    let len = num.toString().length
    while (len < n) {
        num = '0' + num
        len++
    }
    return num
}
export function handlePlayTimeFormat(interval) {
    interval = interval | 0
    const minute = pad((interval / 60) | 0)
    const second = pad(interval % 60)
    return `${minute}:${second}`
}

export function floorTime(num) {
    return Math.floor(num)
}